# import logging
# import os

# def configure_logging():
    

#     # 获取当前脚本所在目录
#     current_dir = os.path.dirname(os.path.abspath(__file__))
#     # 拼接日志文件的绝对路径
#     log_file_path = os.path.join(current_dir, "../log/ocr.log")
    
#     # 配置日志
#     logging.basicConfig(
#         level=logging.INFO,  # 确保日志级别为 INFO
#         format="%(asctime)s - %(levelname)s - %(message)s",
#         handlers=[
#             logging.FileHandler(log_file_path, encoding="utf-8"),
#             logging.StreamHandler()  # 添加控制台输出
#         ]
#     )
#     return logging

# logging = configure_logging()
# logging.info("日志初始化完成")


import os

class My_Logger:
    def __init__(self, log_file_path):
        # 获取当前脚本所在目录
        current_dir = os.path.dirname(os.path.abspath(__file__))
        # 拼接日志文件的绝对路径
        self.log_file_path = os.path.join(current_dir, log_file_path)
        
        # 确保日志目录存在
        log_dir = os.path.dirname(self.log_file_path)
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)
        
        self.info("'——————————————————————————————————————————————————————————————————'")
        self.info("'——————————————————————————————————————————————————————————————————'")
        self.info("'自定义日志初始化完成...'")


    def info(self, *args):
        # 将所有参数拼接成一个字符串
        message = " ".join(map(str, args))
        # 以追加模式打开日志文件并写入内容
        with open(self.log_file_path, 'a', encoding='utf-8') as f:
            f.write(message + '\n')

    def close(self):
        # 显式关闭日志，追加 5 个换行符
        try:
            with open(self.log_file_path, 'a', encoding='utf-8') as f:
                f.write('\n' * 5)
            print("已追加 5 个换行符")
        except Exception as e:
            print(f"Error in close: {e}")



log_file_path = "../log/ocr.log"
logging = My_Logger(log_file_path)
